﻿using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DAL;
using FubiManger.Controls;
namespace FubiManger.UI
{
    partial class EditLevelForm : Smobiler.Core.Controls.MobileForm
    {
        public EditLevelForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        public string merchantid { get; set; }
        List<ms_merchant_level> levellist = new List<ms_merchant_level>();
        List<ms_merchant_level> newlevel = new List<ms_merchant_level>();
        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pansave_Press(object sender, EventArgs e)
        {
            //if (string.IsNullOrEmpty(txtvip1.Text))
            //{
            //    MessageBox.Show("请输入VIP1消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip2.Text))
            //{
            //    MessageBox.Show("请输入VIP2消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip3.Text))
            //{
            //    MessageBox.Show("请输入VIP3消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip4.Text))
            //{
            //    MessageBox.Show("请输入VIP4消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip5.Text))
            //{
            //    MessageBox.Show("请输入VIP5消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip6.Text))
            //{
            //    MessageBox.Show("请输入VIP6消费金额");
            //}
            //else if (string.IsNullOrEmpty(txtvip7.Text))
            //{
            //    MessageBox.Show("请输入VIP7消费金额");
            //}
            //else
            //{
               
            //    for (int i = 0; i < newlevel.Count; i++)
            //    {
            //        merchant_levelDal.Addlevelreul(newlevel[i].merchant_id, newlevel[i].amount.ToString(), newlevel[i].lv_num, newlevel[i].discount_rate);
            //    }
            //    Toast("等级规则设置成功");
            //}
            
            
           // pansave.TouchDisabled = true;
        }

        private void EditLevelForm_Load(object sender, EventArgs e)
        {
            //merchantid = "2";
            levellist = merchant_levelDal.Querybymerid(merchantid);
            if (levellist.Count == 0)
            {
                swlevel.Checked = false;
                panlevels.Height = 7 * 124;
            }
            else
            {
                swlevel.Checked = true;
                swlevel.Enabled = false;
                panlevels.Height = 7 * 124;
                for (int i = 0; i < levellist.Count; i++)
                {
                    leveleditcontrol con = new leveleditcontrol();
                    con.levelname = levellist[i].lv_num;//等级名称
                    con.discount_rate = levellist[i].discount_rate.ToString();//折扣
                    con.merchantid = merchantid;//商户ID
                    con.levelid = levellist[i].id;//等级ID
                    con.amount = levellist[i].amount.ToString();//金额
                    panlevels.Controls.Add(con);
                }
            }
           
            // txtvip_7.Text = (Convert.ToInt32(levellist[7].amount) - 1).ToString();

        }
        /// <summary>
        /// 创建规则
        /// </summary>
        public void Addreul()
        {
            for (int j = 1; j < 8; j++)
            {
                merchant_levelDal.Addlevelreul(merchantid, (100*j).ToString(), "LV" + j, "100");
            }
            levellist = merchant_levelDal.Querybymerid(merchantid);
            panlevels.Height = 7 * 124;
            for (int i = 0; i < levellist.Count; i++)
            {
                leveleditcontrol con = new leveleditcontrol();
                con.levelname = levellist[i].lv_num;//等级名称
                con.discount_rate = levellist[i].discount_rate.ToString();//折扣
                con.merchantid = merchantid;//商户ID
                con.levelid = levellist[i].id;//等级ID
                con.amount = levellist[i].amount.ToString();//金额
                panlevels.Controls.Add(con);
            }
        }
        /// <summary>
        /// 不开启level
        /// </summary>
        public void Closelevel()
        {
            swlevel.Checked = false;
        }
        
      
        /// <summary>
        /// 添加规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void swlevel_CheckedChanged(object sender, EventArgs e)
        {
            if (swlevel.Checked == true)
            {
                Addlevelreulcontrol con = new Addlevelreulcontrol();
                this.Form.ShowDialog(con);
            }

        }
        
    }
}